package com.ruoyi.zhgd.controller;

import java.util.*;

import com.ruoyi.zhgd.util.PageUtils;
import com.ruoyi.zhgd.util.Query;
import com.ruoyi.zhgd.domain.NCementMatch;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.NCementMatchVo;
import com.ruoyi.zhgd.domain.bo.NCementMatchBo;
import com.ruoyi.zhgd.service.INCementMatchService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 水稳拌和楼生产级配
 *
 * @author cj
 * @date 2023-10-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/cementMatch")
public class NCementMatchController extends BaseController {

    private final INCementMatchService iNCementMatchService;

    /**
     * 查询水稳拌和楼生产级配列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<NCementMatchVo> list(NCementMatchBo bo, PageQuery pageQuery) {
        return iNCementMatchService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出水稳拌和楼生产级配列表
     */
    @SaCheckLogin
    @Log(title = "水稳拌和楼生产级配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NCementMatchBo bo, HttpServletResponse response) {
        List<NCementMatchVo> list = iNCementMatchService.queryList(bo);
        ExcelUtil.exportExcel(list, "水稳拌和楼生产级配", NCementMatchVo.class, response);
    }

    /**
     * 获取水稳拌和楼生产级配详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<NCementMatchVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iNCementMatchService.queryById(id));
    }

    /**
     * 新增水稳拌和楼生产级配
     */
    @SaCheckLogin
    @Log(title = "水稳拌和楼生产级配", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NCementMatch bo) {
        return toAjax(iNCementMatchService.insertByBo(bo));
    }

    /**
     * 修改水稳拌和楼生产级配
     */
    @SaCheckLogin
    @Log(title = "水稳拌和楼生产级配", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NCementMatch bo) {
        return toAjax(iNCementMatchService.updateByBo(bo));
    }

    /**
     * 删除水稳拌和楼生产级配
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "水稳拌和楼生产级配", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String ids) {
        return toAjax(iNCementMatchService.deleteWithValidByIds(ids, true));
    }

    /**
    * 获取生产配比列表
    * @author cj
    * @date 2023/10/8 10:42
    * @return 生产配比列表
    **/
    @SaCheckLogin
    @GetMapping("/quList")
    public R<List<NCementMatch>> list(@RequestParam Map<String, Object> params) {
        List<NCementMatch> list = iNCementMatchService.list(params);
        return R.ok(list);
    }

    /**
    * 设计生产配比分页列表
    * @author cj
    * @date 2023/10/8 14:35
    * @return
    **/
    @SaCheckLogin
    @GetMapping("/page")
    public R page(@RequestParam Map<String, Object> params,
                  @RequestParam(value = "pageNum", required = false) Integer pageNum,
                  @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", pageNum);
        paramMap.put("limit", pageSize);
        PageUtils pageUtils = iNCementMatchService.queryPage(new Query(paramMap).getPage(), params);
        return R.ok(pageUtils);
    }

    @SaCheckLogin
    @GetMapping("/info")
    public R info(@RequestParam String id) {
        NCementMatchVo entity = iNCementMatchService.queryById(id);
        if (null == entity) {
            return R.warn("生产配比不存在");
        }
        return R.ok(entity);
    }

}
